package fr.afcepf.atod18.factory;


import java.util.HashMap;
import java.util.Map;

import fr.afcepf.atod18.action.ActionIndex;
import fr.afcepf.atod18.action.ActionLogin;
import fr.afcepf.atod18.action.ActionLogout;
import fr.afcepf.atod18.action.InterfaceAction;

public class Factory {
	
	Map<String, Class> mapFactory  = new HashMap<String, Class>();
	
	public Factory(){
		mapFactory.put("/index.html", ActionIndex.class);
		mapFactory.put("/ActionLogout.do", ActionLogout.class);
		mapFactory.put("/ActionLogin.do", ActionLogin.class);
	}
	
	public InterfaceAction done(String provenance){
		
		Class<InterfaceAction> c = (Class<InterfaceAction>) mapFactory.get(provenance);
		InterfaceAction a = null;
		
		try{
			a = (InterfaceAction)c.newInstance();
		}
		catch (InstantiationException ie){
			ie.printStackTrace();
		}
		catch (IllegalAccessException e){
			e.printStackTrace();
		}
		
		return a; 
		
	}

    /**
     * @return the mapFactory
     */
    public Map<String, Class> getMapFactory() {
        return mapFactory;
    }

    /**
     * @param paramMapFactory the mapFactory to set
     */
    public void setMapFactory(Map<String, Class> paramMapFactory) {
        mapFactory = paramMapFactory;
    }
	
	
	
}
